import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

export default new Vuex.Store({
/*  state: {
    isLoggedIn: localStorage.getItem('token') ? true : false,
  },
  mutations: {
    login(state) {
      state.isLoggedIn = true;
      localStorage.setItem('token', 'true');
    },
    logout(state) {
      state.isLoggedIn = false;
      localStorage.removeItem('token');
    },
  },
  actions: {
    login({ commit }) {
      commit('login');
    },
    logout({ commit }) {
      commit('logout');
    },
  },*/
  state: {
    accessToken: null
  },
  mutations: {
    setAccessToken(state, token) {
      state.accessToken = token;
      sessionStorage.setItem('accessToken', token);
    },
    clearAccessToken(state) {
      state.accessToken = null;
      sessionStorage.removeItem('accessToken');
    }
  },
  actions: {
    login({ commit }, token) {
      commit('setAccessToken', token);
    },
    logout({ commit }) {
      commit('clearAccessToken');
    }
  },
  getters: {
    getAccessToken: state => state.accessToken
  },
});
    